//
//  ReviseViewController.m
//  QuickCare
//
//  Created by lidabiao on 16/7/14.
//  Copyright © 2016年 lidabiao. All rights reserved.
//

#import "ReviseViewController.h"
#import "SSKeychain.h"
#import <SVProgressHUD/SVProgressHUD.h>

@interface ReviseViewController ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *oldPasswordTextField;

@property (weak, nonatomic) IBOutlet UITextField *passwordTextField1;

@property (weak, nonatomic) IBOutlet UITextField *passwordTextField2;

@property (weak, nonatomic) IBOutlet UIButton *doneButton;

@end

@implementation ReviseViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (IBAction)doneButtonClick:(id)sender
{
    NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
    
    NSString *password = [SSKeychain passwordForService:bundleId account: self.userInfo.phoneNum];
    
    if (![self.oldPasswordTextField.text isEqualToString:password])
    {
        NSLog(@"原始密码输入错误");
        
        return;
    }
    if (self.passwordTextField1.text.length < 6)
    {
        NSLog(@"新密码长度不够6位");
      
        [SVProgressHUD showErrorWithStatus:@"新密码长度不够6位"];
        return;
    }
    if (![self.passwordTextField1.text isEqualToString:self.passwordTextField2.text])
    {
        NSLog(@"新密码输入不一致");

        return;
    }
    //修改钥匙串中的密码
    [SSKeychain setPassword:self.passwordTextField1.text forService:bundleId account:self.userInfo.phoneNum];
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
